package com.woniuxy.controller;

import com.woniuxy.pojo.SysRole;
import com.woniuxy.pojo.dto.SysRoleDTO;
import com.woniuxy.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    SysRoleService sysRoleService;



    //角色管理页面加载时获取所有的角色列表
    @GetMapping("/getAllRoles")
    public ResponseEntity<?> getAllRoles(){
        List<SysRoleDTO> sysRoleList = sysRoleService.getAllRoles();
        return ResponseEntity.ok(sysRoleList);
    }

    //修改角色状态
    @PostMapping("/updateStatus")
    public ResponseEntity<?> updateStatus(@RequestBody SysRole sysRole){
        Boolean success = sysRoleService.updateStatus(sysRole);
        return ResponseEntity.ok(success);
    }

    //新增角色
    @PostMapping("/addNewRole")
    public ResponseEntity<?> addNewRole(@RequestBody SysRole sysRole){
        Boolean success = sysRoleService.addNewRole(sysRole);
        return ResponseEntity.ok(success);
    }

    //编辑角色
    @PostMapping("/updateRole")
    public ResponseEntity<?> updateRole(@RequestBody SysRole sysRole){
        Boolean success = sysRoleService.updateRole(sysRole);
        return ResponseEntity.ok(success);
    }

    //删除角色
    @DeleteMapping("/deleteRole/{id}")
    public ResponseEntity<?> deleteRole(@PathVariable Integer id) {
        Boolean success = sysRoleService.deleteRole(id);
        return ResponseEntity.ok(success);
    }





}
